﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NETMovie.UI.WebMVC.Models;
using NETMovie.Entities;

namespace NETMovie.UI.WebMVC.Mappers
{
    public class TransactionMapper
    {
        public ViewRentalCartModel ReMap(Transaction trans)
        {
            ViewRentalCartModel model = new ViewRentalCartModel();
            model.TransactionID = trans.TransactionId;
            model.TransactionNo = trans.TransactionNo;
            model.GST = trans.GST;
            model.TotalAmount = trans.TotalAmount;
            
            if (trans.MovieRentals == null || trans.MovieRentals.Count == 0)
                return model;

            RentalMapper mapper = new RentalMapper();
            model.RentalRecords = new List<ViewRentalRecordModel>();
            List<MovieRental> rentals = trans.MovieRentals.ToList();
            for (int i = 0; i < rentals.Count; i++)
            {
                model.RentalRecords.Add(mapper.ReMap(rentals[i]));
            }

            return model;
        }
    }
}